package com.kevin.es.test;

import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

public class EStest_Doc_Delete_Batch {

    public static void main(String[] args) throws Exception {

        // 创建es客户端
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost", 9200, "http"))
        );

        // 批量插入数据
        BulkRequest request = new BulkRequest();
        DeleteRequest source1 = new DeleteRequest().index("user").id("1001");
        DeleteRequest source2 = new DeleteRequest().index("user").id("1002");
        DeleteRequest source3 = new DeleteRequest().index("user").id("1003");
        request.add(source1).add(source2).add(source3);

        BulkResponse response = client.bulk(request, RequestOptions.DEFAULT);
        System.out.println(response.getTook());
        System.out.println(response.getItems());


        // 关闭es客户端
        client.close();
    }
}
